package com.garfield1.springboottest.controller;

import com.garfield1.springboottest.entity.Book;
import com.garfield1.springboottest.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//RestController相当于是Controller+ResponseBody两个注解，第一个注解为控制器，第二个将返回的数据转成json类型
@RestController
@RequestMapping("/book")
public class BookHandler {

    @Autowired
    private BookRepository bookRepository;

    @GetMapping("/findall")
    public List<Book> ListAll(){
        return bookRepository.findAll();
    }
}
